import service from './service';

const request = {
  post(url: string, params: object) {
    return new Promise((resolve, reject) => {
      service.service.post(url, params).then(res => {
        resolve(res);
      }).catch(err => {
        reject(err);
      });
    });
  },
  get(url: string, params: any) {
    return new Promise((resolve, reject) => {
      service.service.get(url, {params: params}).then(res => {
        resolve(res);
      }).catch(err => {
        reject(err);
      });
    });
  },
  put(url: string, params: object) {
    return new Promise((resolve, reject) => {
      service.service.put(url, params).then(res => {
        resolve(res);
      }).catch(err => {
        reject(err);
      });
    });
  },
  delete(url: string, params: object) {
    return new Promise((resolve, reject) => {
      service.service.delete(url, {params: params}).then(res => {
        resolve(res);
      }).catch(err => {
        reject(err);
      });
    });
  }
};

export default request;
